/*
 * Copyright (c) 2010, Nikolaus Moll
 * All rights reserved.
 */
package net.miblounge.gradecalculator.gui.dialogs;

import net.miblounge.gradecalculator.core.student.Student;
import net.miblounge.gradecalculator.gui.widgets.CourseSelectionWidget;
import net.miblounge.gradecalculator.gui.widgets.SelectionsWidget;
import net.miblounge.gradecalculator.guicommon.dialogs.AbstractDialog;
import net.miblounge.miglayout.qt.MigLayout;

import com.trolltech.qt.gui.QWidget;

public class StudentDialog extends AbstractDialog {
	private final Student student;
	private CourseSelectionWidget groupStudent;
	private SelectionsWidget groupSelections;
	
	public StudentDialog(final QWidget parent, final Student student)
	{
		super(parent);
		this.setWindowTitle("Student");
		this.student = student;
		
		setClientArea(createClientArea());

		// focus student
		
		revalidate();
	}
	
	private QWidget createClientArea()
	{
		final QWidget clientArea = new QWidget();
		
		final MigLayout layout = new MigLayout("", "[grow]", "0[shrink 0][grow]0");

		clientArea.setLayout(layout);
		
		groupStudent = new CourseSelectionWidget(tr("Student"), this, student);
		
		groupSelections = new SelectionsWidget(tr("Select"), this, student);
		
		layout.addWidget(groupStudent, "grow, wrap");
		layout.addWidget(groupSelections, "grow");
		
		return clientArea;
	}
	
	@Override
	public void apply()
	{
		super.apply();
		groupStudent.apply();
		groupSelections.apply();
	}
	
	@Override
	public boolean validate()
	{
		if (!groupStudent.validate()) {
			return false;
		}

		return super.validate();
	}
	
	@Override
	public void revalidate()
	{
		super.revalidate();
		
		groupSelections.setCourseOfStudiesDescription(groupStudent.getCourseOfStudiesDescription());
	}
	
}
